using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Utilities;

namespace GPX
{
    public partial class CompressionParamsDialog : FormEx
    {
        private TrackSegment _TrackSegment;

        public CompressionParamsDialog(TrackSegment trackSegment)
        {
            InitializeComponent();
            _TrackSegment = trackSegment;
        }

        private System.Resources.ResourceManager ResourceManager
        {
            get { return GPXAppResourceManager.ResourceManager; }
        }

        private void CompressionParamsDialog_Load(object sender, EventArgs e)
        {
            Localizer.LocalizeControl(this, ResourceManager);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                double neighbourDistance = double.Parse(txtNeighbourDistance.Text);
                double lineDistance = double.Parse(txtLineDistance.Text);
                double angle = double.Parse(txtNeighbourAngle.Text);

                TrackSegment retVal = _TrackSegment.Compress(neighbourDistance, lineDistance, angle);
                //save it to temporary location
                Track track = new Track();
                track.TrackSegments = new List<TrackSegment>();
                track.TrackSegments.Add(retVal);
                track.Name = "Track #1";
                GPXType gpx = new GPXType();
                gpx.Creator = Defaults.GPXCreator; //"Bernie's GPX Tool";
                gpx.Tracks = new List<Track>();
                gpx.Tracks.Add(track);
                gpx.ToFile(Defaults.GPXSnippetLocation); //@"C:\Temp\Temp.gpx"

                //"The segment has been compressed.\r\n" +
                //"The old segment contained {0} waypoints, the compressed segment {1} waypoints, the rate is {2}%.\r\n" +
                //"The resulting data have been exported to {3}"
                string message = string.Format(ResourceManager.GetString("GPX_CompressionParamsDialog_Message"),
                    _TrackSegment.WayPoints.Count, retVal.WayPoints.Count, 100.0 * (1.0 - (double)retVal.WayPoints.Count / (double)_TrackSegment.WayPoints.Count), Defaults.GPXSnippetLocation);
                MessageBox.Show(message);

                //this.DialogResult = DialogResult.OK;
                //this.Close();
            }
            catch (Exception ex)
            {
                Utils.HandleException(ex);
            }
        }
    }
}